package com.sangmo.fts.teacher.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.Formula;
import com.sangmo.boot.framework.data.json.meta.Many2Many;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.clazz.model.Clazz;
import com.sangmo.fts.common.IConstants;
import com.sangmo.fts.teacher.calculator.ExaminationProcessStateCalculator;
import com.sangmo.fts.teacher.calculator.ExaminationTotalNumberCalculator;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;

/**
 * 实训考核
 */
@Entity
@Table(name = "examination")
@DataView
@ExtView

@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
@Formula(value = "totalNumber", calc = ExaminationTotalNumberCalculator.class, groups = {"Examination.search", "Examination.detail"})
@Formula(value = "processState", calc = ExaminationProcessStateCalculator.class, groups = {"Examination.search", "Examination.detail"})
public class Examination extends SoftDeleteEntity {

    @Many2Many(src="id", value = "clazzs",size = 20,target= Clazz.class, ref="examinationId", targetRef="clazzId", mediator=ExaminationClazz.class, groups = {"default"}, batch = true)

    @DataField(value = IConstants.DATA_TYPE.STRING_10,required = true, index = true, unique = true)
    private String name;

    @DataField(value = IConstants.EXAMINATION_DATA_TYPE.EXAMINATION_BUSINESS_TYPE, required = true, index = true)
    private String businessType;

    @DataField(value = IConstants.EXAMINATION_DATA_TYPE.EXAMINATION_MODE, required = true, index = true)
    private String mode;

    @DataField(value = IConstants.EXAMINATION_DATA_TYPE.EXAMINATION_STATE, required = true, index = true)
    private String state = States.PENDING;

    @DataField(value = IConstants.DATA_TYPE.DATE, required = true)
    private Date startTime;

    @DataField(value = IConstants.DATA_TYPE.DATE, required = true)
    private Date endTime;

    private String description;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getBusinessType() {
        return businessType;
    }

    public void setBusinessType(String businessType) {
        this.businessType = businessType;
    }

    public String getMode() {
        return mode;
    }

    public void setMode(String mode) {
        this.mode = mode;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public interface States {
        String PENDING = "PENDING"; //待评分
        String COMPLETED = "COMPLETED"; //已评分
    }

    public interface Modes {
        String INDIVIDUAL = "INDIVIDUAL";
        String TEAM = "TEAM";
    }

    public interface BusinessTypes {
        //存货质押融资
        String INVENTORY_FINANCING = "INVENTORY_FINANCING"; //IF
        //保兑仓融资
        String CONFIRMING_STORAGE_FINANCING = "CONFIRMING_STORAGE_FINANCING";//CSF
        //应收账款质押融资
        String RECEIVABLE_PLEDGE_FINANCING = "RECEIVABLE_PLEDGE_FINANCING";//RPF
        //保理融资(有追索权明保理)
        String FACTORING_FINANCING = "FACTORING_FINANCING";//FF
    }

    public interface ITotalNumberCalculator {

    }

    public interface IProcessStateCalculator {

    }
}
